package com.ltsh.plugin.mybatis;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.SelectionModel;
import com.intellij.openapi.ui.Messages;

public class MyBatisSqlCoverAction extends AnAction {
    public void actionPerformed(AnActionEvent anActionEvent) {
        Editor mEditor = (Editor) anActionEvent.getData(PlatformDataKeys.EDITOR);
        SelectionModel model = mEditor.getSelectionModel();
        String selectedText = model.getSelectedText();
        if (null != selectedText && !"".equals(selectedText)) {
            ResultObj resultObj = MybatisLogAnalysis.analysisSql(selectedText);
            if (resultObj.isResult()) {
                Messages.showMessageDialog(resultObj.getMessage(), "ltsh-mybatis-log", null);
            } else {
                Messages.showErrorDialog(resultObj.getMessage(), "ltsh-mybatis-log");
            }
        }
    }
}
